package com.gosophia.commons.exception;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;

import org.springframework.util.Assert;

@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name="exceptionDetail")
public class ExceptionDetail   {
    @XmlAttribute
    protected String message;
 
    @XmlAttribute
    private String exceptionErrCode;
    private String[] values;
	public String[] getValues() {
		return values;
	}

	/**
     * 项目代码
     */
    @XmlAttribute
    private String projectCode;
    
    /**
     * 模块代码
     */
    @XmlAttribute
    private String moudleCode;
    
    /**
     * 异常类型码
     */
    @XmlAttribute
    private String typeCode;
    
    /**
     * 异常顺序码
     */
    @XmlAttribute
    private String number;
    
    public ExceptionDetail(){
        
    }

    public ExceptionDetail(String message){
        this.message = message;
    }
    
    public ExceptionDetail(String errorCode ,String message){
        this.message = message;
        this.exceptionErrCode = errorCode;
        splitErrorCode(errorCode);
    }
    
    //新加的方法
    public ExceptionDetail(String errorCode,String message,String[] values){
    	this.message=message;
    	this.exceptionErrCode=errorCode;
    	this.values=values;
    	splitErrorCode(errorCode);
    }
    
    public void setMessage(String message) {
        this.message = message;
    }
    
    public String getMessage() {
        return message;
    }

    public String getErrorCode() {
        return exceptionErrCode.toString();
    }

    public void setErrorCode(String errorCode) {
        this.exceptionErrCode = errorCode;
    }

    public String getProjectCode() {
		return projectCode;
	}

 

	public String getMoudleCode() {
		return moudleCode;
	}

	 

	public String getTypeCode() {
		return typeCode;
	}

 

	public String getNumber() {
		return number;
	}

 
	public String getExceptionErrCode() {
		return exceptionErrCode;
	}

	private void splitErrorCode(String errorCode){
         String[] errCodeSplit = errorCode.split("_");
        Assert.isTrue(errCodeSplit.length == 4, "传入参数格式不正确，请确认异常码有4部分组成，以'_'分隔。");
        this.projectCode = errCodeSplit[0];
        this.moudleCode = errCodeSplit[1];
        this.typeCode = errCodeSplit[2];
        this.number = errCodeSplit[3];
	}
 
}
